# -*- coding: utf-8 -*-
"""
Created on Sun Jan  2 20:30:15 2022

@author: Administrator
"""

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, Date, Float, Text

Base = declarative_base()
engine_cloud = create_engine("mysql+pymysql://root:a123456@localhost:3306/cloud_manage?charset=utf8",pool_recycle=60)
Session_cloud_manage = sessionmaker(autocommit=False, autoflush=True, bind=engine_cloud)
session_cloud_manage = Session_cloud_manage()

# 用户列表
class User_db(Base):  #这里的Site是ORM对象，site_list是数据库中的表格，通过定义类将表site_list与类Site建立了关联
    # 表的名字:
    __tablename__ = 'user'
    # 表的结构:
    username = Column(String(255), primary_key=True)
    password = Column(String(255))
    realname = Column(String(255))
    permission = Column(String(255))
    alias = Column(String(255))

    # 构造函数
    def __init__(self,username,password,realname,permission,alias):
        self.username = username
        self.password = password
        self.realname = realname
        self.permission = permission
        self.alias = alias
    # 打印形式
    def __repr__(self):
        return '<username:{} passwd:{} realname:{} permission:{} alias:{}>'.format(
            self.username,
            self.password,
            self.realname,
            self.permission,
            self.alias,
        )


# 电费
class Cloud_resource(Base):  #这里的Site是ORM对象，site_list是数据库中的表格，通过定义类将表site_list与类Site建立了关联
    # 表的名字:
    # 因为sqlalchemy定义的数据库模型必须要有主见，可以通过这样的定义方式绕过这个规则
    __tablename__  = 'cloud_resource'
    # 表的结构:
    squence = Column(Integer(), primary_key=True)
    applicant_name = Column(String(255))
    applicant_addres = Column(String(255))
    unit_contact = Column(String(255))
    telephone = Column(String(255))
    E_mail = Column(String(255))
    business_system_name = Column(String(255))
    interface_tel = Column(String(255))
    cloud_machine_name = Column(String(255))
    operating_system_version = Column(String(255))
    vCPU_number = Column(Integer())
    memory_G = Column(String(255))
    data_disk = Column(String(255))
    network = Column(String(255))
    firewall_policy = Column(String(255))
    remarks1 = Column(String(255))
    cluster_name = Column(String(255))
    node = Column(String(255))
    server_IP = Column(String(255))
    port_ID = Column(String(255))
    VIP = Column(String(255))
    remarks2 = Column(String(255))
    link_10G_quantity_requirement = Column(String(255))
    special_railway_line = Column(String(255))
    pm_specifications = Column(String(255))
    pm_hostname = Column(String(255))
    pm_operating_system_version = Column(String(255))
    pm_network = Column(String(255))
    pm_firewall_policy = Column(String(255))
    remarks3 = Column(String(255))
    current_link = Column(String(255))
    process = Column(Text())

    # 构造函数
    def __init__(
            self,applicant_name, applicant_addres, unit_contact, telephone, E_mail, business_system_name, interface_tel, cloud_machine_name, operating_system_version, vCPU_number, memory_G, data_disk, network, firewall_policy, remarks1, cluster_name, node, server_IP, port_ID, VIP, remarks2, link_10G_quantity_requirement, special_railway_line, pm_specifications, pm_hostname, pm_operating_system_version, pm_network, pm_firewall_policy, remarks3,current_link,process,
        ):
        self.applicant_name = applicant_name
        self.applicant_addres = applicant_addres
        self.unit_contact = unit_contact
        self.telephone = telephone
        self.E_mail = E_mail
        self.business_system_name = business_system_name
        self.interface_tel = interface_tel
        self.cloud_machine_name = cloud_machine_name
        self.operating_system_version = operating_system_version
        self.vCPU_number = vCPU_number
        self.memory_G = memory_G
        self.data_disk = data_disk
        self.network = network
        self.firewall_policy = firewall_policy
        self.remarks1 = remarks1
        self.cluster_name = cluster_name
        self.node = node
        self.server_IP = server_IP
        self.port_ID = port_ID
        self.VIP = VIP
        self.remarks2 = remarks2
        self.link_10G_quantity_requirement = link_10G_quantity_requirement
        self.special_railway_line = special_railway_line
        self.pm_specifications = pm_specifications
        self.pm_hostname = pm_hostname
        self.pm_operating_system_version = pm_operating_system_version
        self.pm_network = pm_network
        self.pm_firewall_policy = pm_firewall_policy
        self.remarks3 = remarks3
        self.current_link = current_link
        self.process = process


#Base.metadata.clear()
Base.metadata.create_all(engine_cloud) #调用父类Base类中的方法（函数）.create_all创建表结构
session_cloud_manage.commit()    #确认修改
session_cloud_manage.close()     #关闭会话



